﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace RXY_Mall.Core.Tool
{
    public class StringHelper
    {
        public static string HideMobile(string mobile)
        {
            if (!Validator.IsMobile(mobile))
            {
                return mobile;
            }
            return Regex.Replace(mobile, "(\\d{3})\\d{4}(\\d{4})", "$1****$2");
        }

        public static string HideMiddleName(string nick_name)
        {
            if (nick_name.Length < 3)
            {
                return nick_name;
            }
            return nick_name.Substring(0,1) + "***" + nick_name.Substring(nick_name.Length - 1, 1);   
        }

        /// <summary>
        /// 将传入的字符串中间部分字符替换成特殊字符
        /// </summary>
        /// <param name="bank_card">需要替换的字符串</param>
        /// <param name="startLen">前保留长度</param>
        /// <param name="endLen">尾保留长度</param>
        /// <returns>被特殊字符替换的字符串</returns>
        public static string HideBankCard(string bank_card, int startLen = 4, int endLen = 4)
        {
            int lenth = bank_card.Length - startLen - endLen;
            return Regex.Replace(bank_card, "(\\d{" + startLen + "})\\d{" + lenth + "}(\\d{" + endLen + "})", "$1****$2");
        }
    }
}
